package com.sinog.front.controller.biz;

import com.sinog.core.model.UserDTO;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.idempotent.Idempotent;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.SentenceService;
import com.sinog.front.service.user.UserFacade;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @desc 服刑信息增加
 * @author -
 * @date 2020-02-04-14:14
 */
@RestController
public class SentenceController {

    @Resource
    private SentenceService sentenceService;
    @Resource
    private UserFacade userService;

    /**
     * 描述
     * @param codeType codeType
     * @param pCodeId pCodeId
     * @return List<Map<String,Object>>
     */
    @GetMapping("/azbj/inmates/syscode")
    public List<Map<String,Object>> getCodeName(@RequestParam("codeType") String codeType, @RequestParam("pCodeId")String pCodeId){
        return sentenceService.getCodeName(codeType,pCodeId);
    }

    /**
     * 预安置人员信息录入 - 服刑信息tab页 -
     * 犯罪类型下拉 codetype=2_12
     * 现刑期下拉 codetype=1_9
     * 职业技能下拉 codetype=4_1
     * @param codeIds codeIds
     * @return Result
     */
    @PostMapping("/azbj/inmates/sentence/syscode")
    public Result getCodeName(@RequestParam("codeIds") String codeIds) {
        return sentenceService.getCodeName(codeIds);
    }

    /**
     * 预安置人员信息录入 - 保存/更新 服刑信息
     * @param request request
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "保存服刑信息")
    @Idempotent(paramPos = 1)
    @PostMapping("/azbj/sentence/save")
    public Result saveSentenceInfo(HttpServletRequest request,
                                   @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userService.getAuthentication();
        return sentenceService.saveSentenceInfo(data,user);
    }

    /**
     * 预安置人员信息录入 - 保存/更新 服刑信息excel
     * @param request request
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "保存服刑信息")
    @Idempotent(paramPos = 1)
    @PostMapping("/azbj/sentence/saveexcel")
    public Result saveSentenceInfoExcel(HttpServletRequest request,
                                        @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userService.getAuthentication();
        return sentenceService.saveSentenceInfoExcel(data,user);
    }

    /**
     * 根据犯罪编号查询罪犯服刑信息
     * @param prinum prinum
     * @return String
     */
    @PostMapping("/azbj/inmates/getseninfo")
    public String getSentenInfoToEdit(@RequestParam(required = false, defaultValue = "-1") String prinum) {
        return sentenceService.getSenInfoById(prinum);
    }

    /**
     * 根据犯罪编号查询罪犯服刑信息excel
     * @param prinum prinum
     * @return String
     */
    @PostMapping("/azbj/inmates/getseninfoexcel")
    public String getSentenInfoToEditExcel(@RequestParam(required = false, defaultValue = "-1") String prinum) {
        return sentenceService.getSenInfoByIdExcel(prinum);
    }

    /**
     * 预安置人员信息录入 - 服刑信息页面 - 罪名下拉列表
     * @param pageIndex pageIndex
     * @param pageSize pageSize
     * @param codeType codeType
     * @param codeId codeId
     * @param queryKey queryKey
     * @return String
     */
    @RequestMapping("/azbj/inmates/sentence/syscode/zuiming")
    public String getZuiMingList(Integer pageIndex,Integer pageSize,
                                 @RequestParam(required = false, defaultValue = "-1") String codeType,
                                 @RequestParam(required = false, defaultValue = "-1") String codeId,
                                 @RequestParam(required = false, defaultValue = "-1") String queryKey) {
        return sentenceService.getZuiMingList(codeType,codeId,queryKey,pageIndex,pageSize);
    }

    /**
     * 来判断这个服刑人员有没有刑期起止日
     * @param priNum priNum
     * @return String
     */
    @GetMapping("/azbj/inmates/getHasDate")
    public String getHasDate(@RequestParam(required = false, defaultValue = "-1") String priNum) {
        return sentenceService.selectHasDate(priNum);
    }
}